// TestCCCInitConfig tests the Init function
func TestCCCInitConfig(t *testing.T) {
	tmpHome, savedHome := createCCCTmpHome(t)
	defer os.RemoveAll(tmpHome)
	defer os.Setenv("HOME", savedHome)

	var conf cutils.UpdateClientConfig
	err := conf.Init()
	assert.Nil(t, err, "Fail to init config")
}
// TestCCCLoadConfig tests the testdata/home/.dockyard/repo.json file
func TestCCCLoadConfig(t *testing.T) {
	_, path, _, _ := runtime.Caller(0)
	testHome := "/testdata/home"
	savedHome := os.Getenv("HOME")
	defer os.Setenv("HOME", savedHome)
	os.Setenv("HOME", filepath.Join(filepath.Dir(path), testHome))

	var conf cutils.UpdateClientConfig
	err := conf.Load()
	assert.Nil(t, err, "Fail to load config")
	assert.Equal(t, conf.DefaultServer, "containerops.me", "Fail to load 'DefaultServer'")
}
Esempio n. 3
0
		initCommand,
		addCommand,
		removeCommand,
		listCommand,
		pushCommand,
		pullCommand,
		deleteCommand,
		decryptCommand,
	},
}

var initCommand = cli.Command{
	Name:  "init",
	Usage: "initiate default setting",
	Action: func(context *cli.Context) error {
		var ucc cutils.UpdateClientConfig

		if err := ucc.Init(); err != nil {
			fmt.Println(err)
			return err
		}

		fmt.Println("Success in initiating Dockyard Updater Client configuration.")
		return nil
	},
}

var addCommand = cli.Command{
	Name:  "add",
	Usage: "add a repository url",
func TestCCCAddRemoveConfig(t *testing.T) {
	tmpHome, savedHome := createCCCTmpHome(t)
	defer os.RemoveAll(tmpHome)
	defer os.Setenv("HOME", savedHome)

	var conf cutils.UpdateClientConfig
	invalidURL := ""
	validURL := "app#http://containerops/official/duc.rpm"

	// 'add'
	err := conf.Add(invalidURL)
	assert.Equal(t, err, cutils.ErrorsUCInvalidURL)
	err = conf.Add(validURL)
	assert.Nil(t, err, "Failed to add repository")
	err = conf.Add(validURL)
	assert.Equal(t, err, cutils.ErrorsUCRepoExist)

	// 'remove'
	err = conf.Remove(validURL)
	assert.Nil(t, err, "Failed to remove repository")
	err = conf.Remove(validURL)
	assert.Equal(t, err, cutils.ErrorsUCRepoNotExist)
}