コード例 #1
0
ファイル: console_test.go プロジェクト: unirita/s3upadapter
func TestDisplay_メッセージを出力できる(t *testing.T) {
	c := testutil.NewStdoutCapturer()
	c.Start()

	Display("UPA002E", "something error")

	output := c.Stop()

	if output != "UPA002E FAILED TO READ CONFIG FILE. [something error]\n" {
		t.Errorf("stdoutへの出力値[%s]が想定と違います。", output)
	}
}
コード例 #2
0
ファイル: upload_test.go プロジェクト: unirita/s3upadapter
func TestDo_正常系(t *testing.T) {
	makeUploadSuccess()
	defer restoreUploadFunc()

	c := testutil.NewStdoutCapturer()
	c.Start()
	err := Do("testbucket", "testkey", filepath.Join("testdata", "exists.txt"))
	out := c.Stop()

	if err != nil {
		t.Fatalf("想定外のエラーが発生した: %s", err)
	}
	if !strings.Contains(out, "testlocation") {
		t.Error("アップロード先のロケーションが出力されていない。")
	}
}
コード例 #3
0
ファイル: main_test.go プロジェクト: unirita/s3upadapter
func TestRealMain_正常系(t *testing.T) {
	makeUploadSuccess()
	defer restoreUploadFunc()

	c := testutil.NewStdoutCapturer()

	args := new(arguments)
	args.bucketName = "testbucket"
	args.keyName = "testuploadlocation/test.txt"
	args.filePath = "testlocalpath"
	args.configPath = filepath.Join("testdata", "correct.ini")

	c.Start()
	rc := realMain(args)
	c.Stop()

	if rc == rc_ERROR {
		t.Fatalf("想定外のrc[%d]が返された。", rc)
	}

	credentialValue, err := defaults.DefaultConfig.Credentials.Get()
	if err != nil {
		t.Fatalf("クレデンシャル情報の取得に失敗した: %s", err)
	}
	if credentialValue.AccessKeyID != "testaccesskey" {
		t.Errorf("アクセスキーIDの設定値[%s]が想定と違う。", credentialValue.AccessKeyID)
	}
	if credentialValue.SecretAccessKey != "testsecretkey" {
		t.Errorf("シークレットアクセスキーの設定値[%s]が想定と違う。", credentialValue.SecretAccessKey)
	}

	region := defaults.DefaultConfig.Region
	if *region != "testregion" {
		t.Errorf("リージョン名の設定値[%s]が想定と違う。", *region)
	}
}
コード例 #4
0
ファイル: main_test.go プロジェクト: unirita/s3upadapter
func TestRealMain_アップロードに失敗した場合(t *testing.T) {
	makeUploadFail()
	defer restoreUploadFunc()

	c := testutil.NewStdoutCapturer()

	args := new(arguments)
	args.bucketName = "testbucket"
	args.keyName = "testuploadlocation/test.txt"
	args.filePath = "testlocalpath"
	args.configPath = filepath.Join("testdata", "correct.ini")

	c.Start()
	rc := realMain(args)
	out := c.Stop()

	if rc != rc_ERROR {
		t.Errorf("想定外のrc[%d]が返された。", rc)
	}
	if !strings.Contains(out, "UPA004E") {
		t.Error("出力内容が想定と違っている。")
		t.Logf("出力: %s", out)
	}
}