diff options
author | Harald Musum <musum@verizonmedia.com> | 2022-03-15 08:02:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-15 08:02:57 +0100 |
commit | f2d7c0af424036482817cf6efc9407d200cac1ed (patch) | |
tree | 8af35e291c69f8cb85aafe067df8bba5bdb6319c /client/go/cmd/clone_test.go | |
parent | 8e2bc8ab6a4bacbac2f009193a2c83649af35450 (diff) |
Revert "Use entity tag to expire sample apps cache"
Diffstat (limited to 'client/go/cmd/clone_test.go')
-rw-r--r-- | client/go/cmd/clone_test.go | 67 |
1 files changed, 16 insertions, 51 deletions
diff --git a/client/go/cmd/clone_test.go b/client/go/cmd/clone_test.go index 1971e0032a4..9587a1435d3 100644 --- a/client/go/cmd/clone_test.go +++ b/client/go/cmd/clone_test.go @@ -5,10 +5,9 @@ package cmd import ( - "net/http" + "io/ioutil" "os" "path/filepath" - "strings" "testing" "github.com/stretchr/testify/assert" @@ -22,60 +21,28 @@ func TestClone(t *testing.T) { } func assertCreated(sampleAppName string, app string, t *testing.T) { - tempDir := t.TempDir() - app1 := filepath.Join(tempDir, "app1") + appCached := app + "-cache" defer os.RemoveAll(app) + defer os.RemoveAll(appCached) httpClient := &mock.HTTPClient{} - cli, stdout, stderr := newTestCLI(t) - cli.httpClient = httpClient - testdata, err := os.ReadFile(filepath.Join("testdata", "sample-apps-master.zip")) + testdata, err := ioutil.ReadFile(filepath.Join("testdata", "sample-apps-master.zip")) require.Nil(t, err) - - // Initial cloning. GitHub includes the ETag header, but we don't require it httpClient.NextResponseBytes(200, testdata) - require.Nil(t, cli.Run("clone", sampleAppName, app1)) - assert.Equal(t, "Created "+app1+"\n", stdout.String()) - assertFiles(t, app1) - // Clone with cache hit - httpClient.NextStatus(http.StatusNotModified) - stdout.Reset() - app2 := filepath.Join(tempDir, "app2") - require.Nil(t, cli.Run("clone", sampleAppName, app2)) - assert.Equal(t, "Using cached sample apps ...\nCreated "+app2+"\n", stdout.String()) - assertFiles(t, app2) + cli, stdout, _ := newTestCLI(t) + cli.httpClient = httpClient + err = cli.Run("clone", sampleAppName, app) + assert.Nil(t, err) - // Clone while ignoring cache - headers := make(http.Header) - headers.Set("etag", `W/"id1"`) - httpClient.NextResponse(mock.HTTPResponse{Status: 200, Body: testdata, Header: headers}) - stdout.Reset() - app3 := filepath.Join(tempDir, "app3") - require.Nil(t, cli.Run("clone", "-f", sampleAppName, app3)) - assert.Equal(t, "Created "+app3+"\n", stdout.String()) - assertFiles(t, app3) + assert.Equal(t, "Created "+app+"\n", stdout.String()) + assertFiles(t, app) - // Cloning falls back to cached copy if GitHub is unavailable - httpClient.NextStatus(500) stdout.Reset() - app4 := filepath.Join(tempDir, "app4") - require.Nil(t, cli.Run("clone", "-f=false", sampleAppName, app4)) - assert.Equal(t, "Warning: could not download sample apps: github returned status 500\n", stderr.String()) - assert.Equal(t, "Using cached sample apps ...\nCreated "+app4+"\n", stdout.String()) - assertFiles(t, app4) - - // The only cached file is the latest one - dirEntries, err := os.ReadDir(cli.config.cacheDir) - require.Nil(t, err) - var zipFiles []string - for _, de := range dirEntries { - name := de.Name() - if strings.HasPrefix(name, sampleAppsNamePrefix) { - zipFiles = append(zipFiles, name) - } - } - assert.Equal(t, []string{"sample-apps-master_id1.zip"}, zipFiles) + err = cli.Run("clone", sampleAppName, appCached) + assert.Nil(t, err) + assert.Equal(t, "Using cached sample apps ...\nCreated "+appCached+"\n", stdout.String()) + assertFiles(t, appCached) } func assertFiles(t *testing.T, app string) { @@ -83,12 +50,10 @@ func assertFiles(t *testing.T, app string) { assert.True(t, util.PathExists(filepath.Join(app, "src", "main", "application"))) assert.True(t, util.IsDirectory(filepath.Join(app, "src", "main", "application"))) - servicesStat, err := os.Stat(filepath.Join(app, "src", "main", "application", "services.xml")) - require.Nil(t, err) + servicesStat, _ := os.Stat(filepath.Join(app, "src", "main", "application", "services.xml")) servicesSize := int64(1772) assert.Equal(t, servicesSize, servicesStat.Size()) - scriptStat, err := os.Stat(filepath.Join(app, "bin", "convert-msmarco.sh")) - require.Nil(t, err) + scriptStat, _ := os.Stat(filepath.Join(app, "bin", "convert-msmarco.sh")) assert.Equal(t, os.FileMode(0755), scriptStat.Mode()) } |