From 7d6d942ab47696b72c61c12dba63e2b9d654bb26 Mon Sep 17 00:00:00 2001 From: Stanislav Morozov Date: Sat, 11 Apr 2020 00:48:04 +0300 Subject: [PATCH 1/2] Don't add hls_key_info_file to command if it's not present --- .circleci/config.yml | 6 +++--- models/media.go | 6 +++++- models/media_test.go | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 models/media_test.go diff --git a/.circleci/config.yml b/.circleci/config.yml index 39b9cf0..1aba74e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ jobs: build: docker: # specify the version - - image: circleci/golang:1.11 + - image: circleci/golang:1.14 environment: GO111MODULE: "on" @@ -12,5 +12,5 @@ jobs: - checkout # specify any bash command here prefixed with `run: ` - - run: go mod vendor - - run: go test -v ./tests/... \ No newline at end of file + - run: go mod download + - run: go test -failfast -v -run=. ./... diff --git a/models/media.go b/models/media.go index 81482e7..538ade5 100644 --- a/models/media.go +++ b/models/media.go @@ -1138,7 +1138,11 @@ func (m *Mediafile) ObtainMapMetadata() []string { } func (m *Mediafile) ObtainEncryptionKey() []string { - return []string{"-hls_key_info_file", m.encryptionKey} + if m.encryptionKey != "" { + return []string{"-hls_key_info_file", m.encryptionKey} + } + + return nil } func (m *Mediafile) ObtainBframe() []string { diff --git a/models/media_test.go b/models/media_test.go new file mode 100644 index 0000000..ce613b4 --- /dev/null +++ b/models/media_test.go @@ -0,0 +1,21 @@ +package models + +import ( + "github.com/stretchr/testify/require" + "testing" +) + +func TestMedia(t *testing.T) { + t.Run("#ObtainEncryptionKey", func(t *testing.T) { + t.Run("Should get nil if encryptionKey is not set", func(t *testing.T) { + mediaFile := Mediafile{} + + require.Nil(t, mediaFile.ObtainEncryptionKey()) + }) + + t.Run("Should return file.keyinfo if it's set", func(t *testing.T) { + mediaFile := Mediafile{encryptionKey: "file.keyinfo"} + require.Equal(t, []string{"-hls_key_info_file", "file.keyinfo"}, mediaFile.ObtainEncryptionKey()) + }) + }) +} From 644d31a1bc6b9a6aafe5e7352750714811038d37 Mon Sep 17 00:00:00 2001 From: Stanislav Morozov Date: Sat, 11 Apr 2020 00:59:24 +0300 Subject: [PATCH 2/2] Update CI scenario --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1aba74e..0c5b444 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ jobs: build: docker: # specify the version - - image: circleci/golang:1.14 + - image: circleci/golang:1.14-buster environment: GO111MODULE: "on" @@ -12,5 +12,6 @@ jobs: - checkout # specify any bash command here prefixed with `run: ` + - run: sudo apt-get update && sudo apt-get install ffmpeg - run: go mod download - run: go test -failfast -v -run=. ./...