Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
refactor: move GetFileExtension testing function to ./formats_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
namwoam committed Jun 25, 2024
1 parent 1237496 commit 2a42e95
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
26 changes: 0 additions & 26 deletions base/component_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package base

import (
"bufio"
_ "embed"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"os"
"testing"

qt "github.com/frankban/quicktest"
Expand Down Expand Up @@ -53,24 +48,3 @@ func TestComponent_ListConnectorDefinitions(t *testing.T) {
c.Assert(err, qt.IsNil)
c.Check(gotJSON, qt.JSONEquals, wantConnectorDefinitionStruct)
}

func TestUtil_GetFileExtension(t *testing.T) {
c := qt.New(t)

file, err := os.Open("./testdata/test_image.png")
c.Assert(err, qt.IsNil)
defer file.Close()
wantFileExtension := "png"

reader := bufio.NewReader(file)
content, err := io.ReadAll(reader)
c.Assert(err, qt.IsNil)

fileBase64 := base64.StdEncoding.EncodeToString(content)
fileBase64 = "data:image/png;base64," + fileBase64
fmt.Println(fileBase64)
gotFileExtension := GetBase64FileExtensionSlow(fileBase64)
c.Check(gotFileExtension, qt.Equals, wantFileExtension)
gotFileExtension = GetBase64FileExtensionFast(fileBase64)
c.Check(gotFileExtension, qt.Equals, wantFileExtension)
}
33 changes: 33 additions & 0 deletions base/formats_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package base

import (
"bufio"
"encoding/base64"
"fmt"
"io"
"os"
"testing"

qt "github.com/frankban/quicktest"
)

func TestUtil_GetFileExtension(t *testing.T) {
c := qt.New(t)

file, err := os.Open("./testdata/test_image.png")
c.Assert(err, qt.IsNil)
defer file.Close()
wantFileExtension := "png"

reader := bufio.NewReader(file)
content, err := io.ReadAll(reader)
c.Assert(err, qt.IsNil)

fileBase64 := base64.StdEncoding.EncodeToString(content)
fileBase64 = "data:image/png;base64," + fileBase64
fmt.Println(fileBase64)
gotFileExtension := GetBase64FileExtensionSlow(fileBase64)
c.Check(gotFileExtension, qt.Equals, wantFileExtension)
gotFileExtension = GetBase64FileExtensionFast(fileBase64)
c.Check(gotFileExtension, qt.Equals, wantFileExtension)
}

0 comments on commit 2a42e95

Please sign in to comment.