|
6 | 6 | "fmt" |
7 | 7 | "net/http" |
8 | 8 | "net/http/httptest" |
| 9 | + "os" |
| 10 | + "path/filepath" |
9 | 11 | "testing" |
10 | 12 |
|
11 | 13 | "github.com/docker/docker/api/types/container" |
@@ -93,8 +95,50 @@ func TestLicenseValidationFailure(t *testing.T) { |
93 | 95 | assert.Error(t, err, "container should not exist after license failure") |
94 | 96 | } |
95 | 97 |
|
| 98 | +func licenseFilePath(t *testing.T) string { |
| 99 | + t.Helper() |
| 100 | + cacheDir, err := os.UserCacheDir() |
| 101 | + require.NoError(t, err) |
| 102 | + return filepath.Join(cacheDir, "lstk", "license.json") |
| 103 | +} |
| 104 | + |
96 | 105 | func cleanupLicense() { |
97 | 106 | ctx := context.Background() |
98 | 107 | _ = dockerClient.ContainerStop(ctx, containerName, container.StopOptions{}) |
99 | 108 | _ = dockerClient.ContainerRemove(ctx, containerName, container.RemoveOptions{Force: true}) |
| 109 | + if cacheDir, err := os.UserCacheDir(); err == nil { |
| 110 | + _ = os.Remove(filepath.Join(cacheDir, "lstk", "license.json")) |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +func TestLicenseCacheAndMount(t *testing.T) { |
| 115 | + requireDocker(t) |
| 116 | + env.Require(t, env.AuthToken) |
| 117 | + |
| 118 | + cleanupLicense() |
| 119 | + t.Cleanup(cleanupLicense) |
| 120 | + |
| 121 | + licenseBody := `{"license":"test-license-data"}` |
| 122 | + mockServer := createMockLicenseServerWithBody(licenseBody) |
| 123 | + defer mockServer.Close() |
| 124 | + |
| 125 | + ctx := testContext(t) |
| 126 | + _, stderr, err := runLstk(t, ctx, "", env.With(env.APIEndpoint, mockServer.URL), "start") |
| 127 | + require.NoError(t, err, "lstk start failed: %s", stderr) |
| 128 | + |
| 129 | + data, err := os.ReadFile(licenseFilePath(t)) |
| 130 | + require.NoError(t, err, "license cache file should exist after successful start") |
| 131 | + assert.Equal(t, licenseBody, string(data)) |
| 132 | + |
| 133 | + inspect, err := dockerClient.ContainerInspect(ctx, containerName) |
| 134 | + require.NoError(t, err, "failed to inspect container") |
| 135 | + |
| 136 | + var mounted bool |
| 137 | + for _, m := range inspect.Mounts { |
| 138 | + if m.Destination == "/etc/localstack/conf.d/license.json" { |
| 139 | + mounted = true |
| 140 | + break |
| 141 | + } |
| 142 | + } |
| 143 | + assert.True(t, mounted, "license file should be mounted into container at /etc/localstack/conf.d/license.json") |
100 | 144 | } |
0 commit comments