object_tagging_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package basic
  2. import (
  3. "fmt"
  4. "github.com/aws/aws-sdk-go/aws"
  5. "github.com/aws/aws-sdk-go/service/s3"
  6. "testing"
  7. )
  8. func TestObjectTagging(t *testing.T) {
  9. input := &s3.PutObjectInput{
  10. Bucket: aws.String("theBucket"),
  11. Key: aws.String("testDir/testObject"),
  12. }
  13. svc.PutObject(input)
  14. printTags()
  15. setTags()
  16. printTags()
  17. clearTags()
  18. printTags()
  19. }
  20. func printTags() {
  21. response, err := svc.GetObjectTagging(
  22. &s3.GetObjectTaggingInput{
  23. Bucket: aws.String("theBucket"),
  24. Key: aws.String("testDir/testObject"),
  25. })
  26. fmt.Println("printTags")
  27. if err != nil {
  28. fmt.Println(err.Error())
  29. }
  30. fmt.Println(response.TagSet)
  31. }
  32. func setTags() {
  33. response, err := svc.PutObjectTagging(&s3.PutObjectTaggingInput{
  34. Bucket: aws.String("theBucket"),
  35. Key: aws.String("testDir/testObject"),
  36. Tagging: &s3.Tagging{
  37. TagSet: []*s3.Tag{
  38. {
  39. Key: aws.String("kye2"),
  40. Value: aws.String("value2"),
  41. },
  42. },
  43. },
  44. })
  45. fmt.Println("setTags")
  46. if err != nil {
  47. fmt.Println(err.Error())
  48. }
  49. fmt.Println(response.String())
  50. }
  51. func clearTags() {
  52. response, err := svc.DeleteObjectTagging(&s3.DeleteObjectTaggingInput{
  53. Bucket: aws.String("theBucket"),
  54. Key: aws.String("testDir/testObject"),
  55. })
  56. fmt.Println("clearTags")
  57. if err != nil {
  58. fmt.Println(err.Error())
  59. }
  60. fmt.Println(response.String())
  61. }