Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions control/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ func TestListDomainSubscriber(t *testing.T) {
RelayState.RedisClient.FlushAll(context.TODO()).Result()

app := configCmdInit()

file, err := os.Open("../misc/test/exampleConfig.json")
if err != nil {
t.Fatalf("Failed to open test resource file: %v", err)
}
defer file.Close()

jsonData, _ := io.ReadAll(file)

app.SetArgs([]string{"import", "--data", string(jsonData)})
Expand Down Expand Up @@ -45,10 +48,13 @@ func TestListDomainLimited(t *testing.T) {
RelayState.RedisClient.FlushAll(context.TODO()).Result()

app := configCmdInit()

file, err := os.Open("../misc/test/exampleConfig.json")
if err != nil {
t.Fatalf("Failed to open test resource file: %v", err)
}
defer file.Close()

jsonData, _ := io.ReadAll(file)

app.SetArgs([]string{"import", "--data", string(jsonData)})
Expand Down Expand Up @@ -76,10 +82,13 @@ func TestListDomainBlocked(t *testing.T) {
RelayState.RedisClient.FlushAll(context.TODO()).Result()

app := configCmdInit()

file, err := os.Open("../misc/test/exampleConfig.json")
if err != nil {
t.Fatalf("Failed to open test resource file: %v", err)
}
defer file.Close()

jsonData, _ := io.ReadAll(file)

app.SetArgs([]string{"import", "--data", string(jsonData)})
Expand Down Expand Up @@ -149,10 +158,13 @@ func TestUnsetDomainBlocked(t *testing.T) {
RelayState.RedisClient.FlushAll(context.TODO()).Result()

app := configCmdInit()

file, err := os.Open("../misc/test/exampleConfig.json")
if err != nil {
t.Fatalf("Failed to open test resource file: %v", err)
}
defer file.Close()

jsonData, _ := io.ReadAll(file)

app.SetArgs([]string{"import", "--data", string(jsonData)})
Expand All @@ -179,10 +191,13 @@ func TestUnsetDomainLimited(t *testing.T) {
RelayState.RedisClient.FlushAll(context.TODO()).Result()

app := configCmdInit()

file, err := os.Open("../misc/test/exampleConfig.json")
if err != nil {
t.Fatalf("Failed to open test resource file: %v", err)
}
defer file.Close()

jsonData, _ := io.ReadAll(file)

app.SetArgs([]string{"import", "--data", string(jsonData)})
Expand All @@ -209,10 +224,13 @@ func TestSetDomainInvalid(t *testing.T) {
RelayState.RedisClient.FlushAll(context.TODO()).Result()

app := configCmdInit()

file, err := os.Open("../misc/test/exampleConfig.json")
if err != nil {
t.Fatalf("Failed to open test resource file: %v", err)
}
defer file.Close()

jsonData, _ := io.ReadAll(file)

app.SetArgs([]string{"import", "--data", string(jsonData)})
Expand All @@ -236,10 +254,13 @@ func TestUnfollowDomain(t *testing.T) {
RelayState.RedisClient.FlushAll(context.TODO()).Result()

app := configCmdInit()

file, err := os.Open("../misc/test/exampleConfig.json")
if err != nil {
t.Fatalf("Failed to open test resource file: %v", err)
}
defer file.Close()

jsonData, _ := io.ReadAll(file)

app.SetArgs([]string{"import", "--data", string(jsonData)})
Expand All @@ -266,10 +287,13 @@ func TestInvalidUnfollowDomain(t *testing.T) {
RelayState.RedisClient.FlushAll(context.TODO()).Result()

app := configCmdInit()

file, err := os.Open("../misc/test/exampleConfig.json")
if err != nil {
t.Fatalf("Failed to open test resource file: %v", err)
}
defer file.Close()

jsonData, _ := io.ReadAll(file)

app.SetArgs([]string{"import", "--data", string(jsonData)})
Expand Down
15 changes: 6 additions & 9 deletions control/utils.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
package control

import "slices"

import "github.com/yukimochi/Activity-Relay/models"

func contains(entries interface{}, key string) bool {
func contains(entries any, key string) bool {
switch entry := entries.(type) {
case string:
return entry == key
case []string:
for i := 0; i < len(entry); i++ {
if entry[i] == key {
return true
}
}
return false
return slices.Contains(entry, key)
case []models.Subscriber:
for i := 0; i < len(entry); i++ {
for i := range entry {
if entry[i].Domain == key {
return true
}
}
return false
case []models.Follower:
for i := 0; i < len(entry); i++ {
for i := range entry {
if entry[i].Domain == key {
return true
}
Expand Down