github.com/confluentinc/cli@v1.100.0/test/local_test.go (about)

     1  package test
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func (s *CLITestSuite) TestLocalLifecycle() {
    12  	s.createCH([]string{
    13  		"share/java/confluent-control-center/control-center-5.5.0.jar",
    14  	})
    15  	s.createCC()
    16  	defer s.destroy()
    17  
    18  	tests := []CLITest{
    19  		{args: "local destroy", fixture: "local/destroy-error.golden", wantErrCode: 1},
    20  		{args: "local current", fixture: "local/current.golden", regex: true},
    21  		{args: "local destroy", fixture: "local/destroy.golden", regex: true},
    22  	}
    23  
    24  	loginURL := serveMds(s.T()).URL
    25  
    26  	for _, tt := range tests {
    27  		tt.workflow = true
    28  		s.runConfluentTest(tt, loginURL)
    29  	}
    30  }
    31  
    32  func (s *CLITestSuite) TestLocalConfluentCommunitySoftware() {
    33  	s.createCH([]string{
    34  		"share/java/confluent-common/common-config-5.5.0.jar",
    35  	})
    36  	defer s.destroy()
    37  
    38  	tests := []CLITest{
    39  		{args: "local services list", fixture: "local/services-list-ccs.golden"},
    40  		{args: "local version", fixture: "local/version-ccs.golden"},
    41  	}
    42  
    43  	loginURL := serveMds(s.T()).URL
    44  
    45  	for _, tt := range tests {
    46  		s.runConfluentTest(tt, loginURL)
    47  	}
    48  }
    49  
    50  func (s *CLITestSuite) TestLocalVersion() {
    51  	s.createCH([]string{
    52  		"share/java/confluent-control-center/control-center-5.5.0.jar",
    53  		"share/java/kafka-connect-replicator/connect-replicator-5.5.0.jar",
    54  	})
    55  	defer s.destroy()
    56  
    57  	tests := []CLITest{
    58  		{args: "local version", fixture: "local/version-cp.golden"},
    59  	}
    60  
    61  	loginURL := serveMds(s.T()).URL
    62  
    63  	for _, tt := range tests {
    64  		s.runConfluentTest(tt, loginURL)
    65  	}
    66  }
    67  
    68  func (s *CLITestSuite) TestLocalServicesList() {
    69  	s.createCH([]string{
    70  		"share/java/confluent-control-center/control-center-5.5.0.jar",
    71  	})
    72  	defer s.destroy()
    73  
    74  	tests := []CLITest{
    75  		{args: "local services list", fixture: "local/services-list-cp.golden"},
    76  	}
    77  
    78  	loginURL := serveMds(s.T()).URL
    79  
    80  	for _, tt := range tests {
    81  		s.runConfluentTest(tt, loginURL)
    82  	}
    83  }
    84  
    85  func (s *CLITestSuite) TestLocalServicesLifecycle() {
    86  	s.createCH([]string{
    87  		"share/java/confluent-control-center/control-center-5.5.0.jar",
    88  	})
    89  	defer s.destroy()
    90  
    91  	tests := []CLITest{
    92  		{args: "local services status", fixture: "local/services-status-all-stopped.golden", regex: true},
    93  		{args: "local services stop", fixture: "local/services-stop-already-stopped.golden", regex: true},
    94  		{args: "local services top", fixture: "local/services-top-no-services-running.golden", wantErrCode: 1},
    95  	}
    96  
    97  	loginURL := serveMds(s.T()).URL
    98  
    99  	for _, tt := range tests {
   100  		s.runConfluentTest(tt, loginURL)
   101  	}
   102  }
   103  
   104  func (s *CLITestSuite) TestLocalZookeeperLifecycle() {
   105  	s.createCH([]string{
   106  		"share/java/kafka/zookeeper-5.5.0.jar",
   107  	})
   108  	defer s.destroy()
   109  
   110  	tests := []CLITest{
   111  		{args: "local services zookeeper log", fixture: "local/zookeeper-log-error.golden", wantErrCode: 1},
   112  		{args: "local services zookeeper status", fixture: "local/zookeeper-status-stopped.golden", regex: true},
   113  		{args: "local services zookeeper stop", fixture: "local/zookeeper-stop-already-stopped.golden", regex: true},
   114  		{args: "local services zookeeper top", fixture: "local/zookeeper-top-stopped.golden"},
   115  		{args: "local services zookeeper version", fixture: "local/zookeeper-version.golden"},
   116  	}
   117  
   118  	loginURL := serveMds(s.T()).URL
   119  
   120  	for _, tt := range tests {
   121  		s.runConfluentTest(tt, loginURL)
   122  	}
   123  }
   124  
   125  func (s *CLITestSuite) createCC() {
   126  	req := require.New(s.T())
   127  
   128  	dir := filepath.Join(os.TempDir(), "confluent-int-test", "cc")
   129  	req.NoError(os.Setenv("CONFLUENT_CURRENT", dir))
   130  }
   131  
   132  func (s *CLITestSuite) createCH(files []string) {
   133  	req := require.New(s.T())
   134  
   135  	dir := filepath.Join(os.TempDir(), "confluent-int-test", "ch")
   136  	req.NoError(os.Setenv("CONFLUENT_HOME", dir))
   137  
   138  	for _, file := range files {
   139  		path := filepath.Join(dir, file)
   140  
   141  		dir := filepath.Dir(path)
   142  		req.NoError(os.MkdirAll(dir, 0777))
   143  
   144  		req.NoError(ioutil.WriteFile(path, []byte{}, 0644))
   145  	}
   146  }
   147  
   148  func (s *CLITestSuite) destroy() {
   149  	req := require.New(s.T())
   150  
   151  	req.NoError(os.Setenv("CONFLUENT_HOME", ""))
   152  	req.NoError(os.Setenv("CONFLUENT_CURRENT", ""))
   153  	dir := filepath.Join(os.TempDir(), "confluent-int-test")
   154  	req.NoError(os.RemoveAll(dir))
   155  }