github.com/confluentinc/cli@v1.100.0/test/update_test.go (about) 1 package test 2 3 import ( 4 "io/ioutil" 5 "os" 6 7 "github.com/atrox/homedir" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func (s *CLITestSuite) TestUpdate() { 12 s.T().Skip("Skipping this test until its less flaky") 13 14 configFile, err := homedir.Expand("~/.confluent/config.json") 15 require.NoError(s.T(), err) 16 17 // Remove the cache file so we'll see the update prompt 18 path, err := homedir.Expand("~/.confluent/update_check") 19 require.NoError(s.T(), err) 20 err = os.RemoveAll(path) // RemoveAll so we don't return an error if file doesn't exist 21 require.NoError(s.T(), err) 22 23 // Be nice and restore the config when we're done 24 oldConfig, err := ioutil.ReadFile(configFile) 25 require.NoError(s.T(), err) 26 defer func() { 27 err := ioutil.WriteFile(configFile, oldConfig, 600) 28 require.NoError(s.T(), err) 29 }() 30 31 // Reset the config to a known empty state 32 err = ioutil.WriteFile(configFile, []byte(`{}`), 600) 33 require.NoError(s.T(), err) 34 35 tests := []CLITest{ 36 {args: "version", fixture: "update1.golden", regex: true}, 37 {args: "--help", contains: "Update the confluent CLI."}, 38 {name: "HACK: disable update checks"}, 39 {args: "version", fixture: "update2.golden", regex: true}, 40 {args: "--help", contains: "Update the confluent CLI."}, 41 {name: "HACK: enabled checks, disable updates"}, 42 {args: "version", fixture: "update2.golden", regex: true}, 43 {args: "--help", notContains: "Update the confluent CLI."}, 44 } 45 46 loginURL := serveMds(s.T()).URL 47 48 for _, tt := range tests { 49 tt.workflow = true 50 switch tt.name { 51 case "HACK: disable update checks": 52 err = ioutil.WriteFile(configFile, []byte(`{"disable_update_checks": true}`), os.ModePerm) 53 require.NoError(s.T(), err) 54 case "HACK: enabled checks, disable updates": 55 err = ioutil.WriteFile(configFile, []byte(`{"disable_updates": true}`), os.ModePerm) 56 require.NoError(s.T(), err) 57 default: 58 s.runConfluentTest(tt, loginURL) 59 if tt.fixture == "update1.golden" { 60 // Remove the cache file so it _would_ prompt again (if not disabled) 61 err = os.RemoveAll(path) // RemoveAll so we don't return an error if file doesn't exist 62 require.NoError(s.T(), err) 63 } 64 } 65 } 66 }