|
| 1 | +// Copyright 2024 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License |
| 14 | + |
| 15 | +package videostitcher |
| 16 | + |
| 17 | +import ( |
| 18 | + "bytes" |
| 19 | + "fmt" |
| 20 | + "strings" |
| 21 | + "testing" |
| 22 | + "time" |
| 23 | + |
| 24 | + "github.com/GoogleCloudPlatform/golang-samples/internal/testutil" |
| 25 | +) |
| 26 | + |
| 27 | +func TestGetLiveAdTagDetail(t *testing.T) { |
| 28 | + tc := testutil.SystemTest(t) |
| 29 | + var buf bytes.Buffer |
| 30 | + uuid, err := getUUID() |
| 31 | + if err != nil { |
| 32 | + t.Fatalf("getUUID err: %v", err) |
| 33 | + } |
| 34 | + slateID := fmt.Sprintf("%s-%s", slateIDPrefix, uuid) |
| 35 | + slateName := fmt.Sprintf("projects/%s/locations/%s/slates/%s", tc.ProjectID, location, slateID) |
| 36 | + liveConfigID := fmt.Sprintf("%s-%s", liveConfigIDPrefix, uuid) |
| 37 | + liveConfigName := fmt.Sprintf("projects/%s/locations/%s/liveConfigs/%s", tc.ProjectID, location, liveConfigID) |
| 38 | + |
| 39 | + createTestSlate(slateID, t) |
| 40 | + createTestLiveConfig(slateID, liveConfigID, t) |
| 41 | + t.Cleanup(func() { |
| 42 | + // Can't delete live sessions |
| 43 | + deleteTestLiveConfig(liveConfigName, t) |
| 44 | + deleteTestSlate(slateName, t) |
| 45 | + }) |
| 46 | + |
| 47 | + sessionID, playURI := createTestLiveSession(liveConfigID, t) |
| 48 | + |
| 49 | + // No list or delete methods for live sessions |
| 50 | + |
| 51 | + // Ad tag details |
| 52 | + |
| 53 | + // To get ad tag details, you need to curl the main manifest and |
| 54 | + // a rendition first. This supplies media player information to the API. |
| 55 | + // |
| 56 | + // Get the playURI first. The last line of the response will contain a |
| 57 | + // renditions location. Curl the live session name with the rendition |
| 58 | + // location appended. |
| 59 | + |
| 60 | + renditions, err := getPlayURI(playURI) |
| 61 | + if err != nil { |
| 62 | + t.Fatalf("getPlayURI err: %v", err) |
| 63 | + } |
| 64 | + |
| 65 | + // playURI will be in the following format: |
| 66 | + // https://videostitcher.googleapis.com/v1/projects/{project}/locations/{location}/liveSessions/{session-id}/manifest.m3u8?signature=... |
| 67 | + // Replace manifest.m3u8?signature=... with the renditions location. |
| 68 | + |
| 69 | + err = curlRendition(playURI, renditions[0]) |
| 70 | + if err != nil { |
| 71 | + t.Fatalf("curlRendition err: %v", err) |
| 72 | + } |
| 73 | + |
| 74 | + // List the ad tag details for a given live session. This is the only way to get an |
| 75 | + // ad tag detail. |
| 76 | + adTagDetailsNamePrefix := fmt.Sprintf("/locations/%s/liveSessions/%s/liveAdTagDetails/", location, sessionID) |
| 77 | + if err := listLiveAdTagDetails(&buf, tc.ProjectID, sessionID); err != nil { |
| 78 | + t.Fatalf("listLiveAdTagDetails got err: %v", err) |
| 79 | + } |
| 80 | + got := buf.String() |
| 81 | + |
| 82 | + if !strings.Contains(got, adTagDetailsNamePrefix) { |
| 83 | + t.Fatalf("listLiveAdTagDetails got\n----\n%v\n----\nWant to contain:\n----\n%v\n----\n", got, adTagDetailsNamePrefix) |
| 84 | + } |
| 85 | + strSlice := strings.Split(got, "/") |
| 86 | + adTagDetailsID := strSlice[len(strSlice)-1] |
| 87 | + adTagDetailsID = strings.TrimRight(adTagDetailsID, "\n") |
| 88 | + adTagDetailsName := fmt.Sprintf("/locations/%s/liveSessions/%s/liveAdTagDetails/%s", location, sessionID, adTagDetailsID) |
| 89 | + if !strings.Contains(got, adTagDetailsName) { |
| 90 | + t.Errorf("listLiveAdTagDetails got\n----\n%v\n----\nWant to contain:\n----\n%v\n----\n", got, adTagDetailsName) |
| 91 | + } |
| 92 | + buf.Reset() |
| 93 | + |
| 94 | + // Get the specified ad tag detail for a given live session. |
| 95 | + testutil.Retry(t, 3, 2*time.Second, func(r *testutil.R) { |
| 96 | + if err := getLiveAdTagDetail(&buf, tc.ProjectID, sessionID, adTagDetailsID); err != nil { |
| 97 | + r.Errorf("getLiveAdTagDetail got err: %v", err) |
| 98 | + } |
| 99 | + if got := buf.String(); !strings.Contains(got, adTagDetailsName) { |
| 100 | + r.Errorf("getLiveAdTagDetail got\n----\n%v\n----\nWant to contain:\n----\n%v\n----\n", got, adTagDetailsName) |
| 101 | + } |
| 102 | + }) |
| 103 | + buf.Reset() |
| 104 | +} |
0 commit comments