// TestOper tests add/get/getmeta/getmetasign/list
func TestOper(t *testing.T) {
	var appV1Repo client.UpdateClientAppV1Repo

	validURL := getTestURL()

	// Skip the test if the testing enviornment is not ready
	if validURL == "" {
		fmt.Printf("Skip the '%s' test since the testing enviornment is not ready.\n", "List")
		return
	}

	testFiles := []string{"osA/archA/appA", "osB/archB/appB"}

	f, _ := appV1Repo.New(validURL)
	defer func() {
		for _, tf := range testFiles {
			err := f.Delete(tf)
			assert.Nil(t, err, "Fail to delete file")
		}
	}()

	// Init the data and also test the put function
	_, path, _, _ := runtime.Caller(0)
	for _, tf := range testFiles {
		file := filepath.Join(filepath.Dir(path), "testdata", tf)
		content, _ := ioutil.ReadFile(file)
		err := f.Put(tf, content, utils.EncryptNone)
		assert.Nil(t, err, "Fail to put file")
	}

	// Test list
	l, err := f.List()
	assert.Nil(t, err, "Fail to list")
	assert.Equal(t, len(l), 2, "Fail to list or something wrong in put")
	ok := (l[0] == testFiles[0] && l[1] == testFiles[1]) || (l[0] == testFiles[1] && l[1] == testFiles[0])
	assert.Equal(t, true, ok, "Fail to list the correct data")

	// Test get file
	fileBytes, err := f.GetFile(testFiles[0])
	assert.Nil(t, err, "Fail to get file")
	expectedBytes, _ := ioutil.ReadFile(filepath.Join(filepath.Dir(path), "testdata", testFiles[0]))
	assert.Equal(t, fileBytes, expectedBytes, "Fail to get the correct data")

	// Test get meta
	metaBytes, err := f.GetMeta()
	assert.Nil(t, err, "Fail to get meta file")

	// Test get metasign
	signBytes, err := f.GetMetaSign()
	assert.Nil(t, err, "Fail to get meta signature file")

	// Test get public key
	pubkeyBytes, err := f.GetPublicKey()
	assert.Nil(t, err, "Fail to get public key file")

	// VIP: Verify meta/sign with public to make real sure that everything works perfect
	err = utils.SHA256Verify(pubkeyBytes, metaBytes, signBytes)
	assert.Nil(t, err, "Fail to verify the meta data")
}
// TestMCRAppV1New
func TestMCRAppV1New(t *testing.T) {
	var appV1 client.UpdateClientAppV1Repo

	invalidURL := "containerops.me/containerops/official"
	_, err := appV1.New(invalidURL)
	assert.Equal(t, err, client.ErrorsUCRepoInvalid, "Fail to parse invalid url")

	invalidURL2 := "http://containerops.me/containerops"
	_, err = appV1.New(invalidURL2)
	assert.Equal(t, err, client.ErrorsUCRepoInvalid, "Fail to parse invalid url")

	validURL := "http://containerops.me/containerops/official"
	f, err := appV1.New(validURL)
	assert.Nil(t, err, "Fail to setup a valid repo")
	assert.Equal(t, f.String(), validURL, "Fail to parse url")
	assert.Equal(t, f.NRString(), "containerops/official", "Fail to parse url")
}